package com.ruoyi.common.core.aspect;

import com.ruoyi.common.core.annotation.FieldValueConvert;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * 字段值转换
 *
 * @author ZhangYu
 * @date 2024-04-30
 */
@Aspect
@Component
public class FieldValueConvertAspect {

    @Pointcut("@annotation(com.ruoyi.common.core.annotation.FieldValueConvert)")
    public void fieldValueConvertPointcut() {

    }

    /**
     * 日志记录
     *
     * @param joinPoint 切入点参数
     */
    @Before("fieldValueConvertPointcut()")
    public void fieldValueConvertAspectBefore(JoinPoint joinPoint) {
        System.out.println("_--------------------------------------------------111111111111111111111111111111111111111");
    }

    /**
     * 日志记录
     *
     * @param joinPoint 切入点参数
     */
    @AfterReturning(pointcut = "fieldValueConvertPointcut()", returning = "object")
    public Object fieldValueConvertAspect(JoinPoint joinPoint, Object object) {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        FieldValueConvert fieldValueConvert = method.getAnnotation(FieldValueConvert.class);
        System.out.println("_--------------------------------------------------222222222222222222222222222222222222222");
        return "s";
    }

    /**
     * 日志记录
     *
     * @param joinPoint 切入点参数
     */
    @AfterThrowing(pointcut = "fieldValueConvertPointcut()", throwing = "exception")
    public Object fieldValueConvertAspect(JoinPoint joinPoint, Exception exception) {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        FieldValueConvert fieldValueConvert = method.getAnnotation(FieldValueConvert.class);
        System.out.println("_--------------------------------------------------444444444444444444444444444444444444444");
        return "s";
    }

}
